home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / elk-2_0.lha / elk-2.0 / contrib / zelk / src-zlib / filetimes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-17  |  954 b   |  63 lines

  1. /* filetimes.c  - get file times
  2.  * 24sep
  3.  * 18feb        remove curtime,timestring to minilibz
  4.  * 3dec.  successful sysV port
  5.  */
  6.  
  7. #include <theusual.h>
  8.  
  9. #if !Eunix
  10. : error unix version
  11. #endif
  12.  
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #include <sys/time.h>
  16.  
  17.  
  18.  
  19. Ztime_t Zfilemodtime(path)
  20.   char *path;
  21. {
  22.   struct stat buf;
  23.   if (stat(path,&buf) < 0) return 0;
  24.   return( (long)buf.st_mtime );
  25. }
  26.  
  27.  
  28. Ztime_t Zfileacctime(path)
  29.   char *path;
  30. {
  31.   struct stat buf;
  32.   if (stat(path,&buf) < 0) return 0;
  33.   return( (Ztime_t)buf.st_atime );
  34. }
  35.  
  36. proc Zfilesettimes(path, acc,mod)
  37.     char *path;
  38.     Ztime_t acc,mod;
  39. {
  40.     struct timeval tv[2];
  41.  
  42.     tv[0].tv_sec = acc;
  43.     tv[1].tv_sec = mod;
  44.     tv[0].tv_usec = tv[1].tv_usec = 0;
  45.     if (utimes(path, tv) < 0) {
  46.         fprintf(stderr, "filesettimes: can't set time on %s: ", path);
  47.         perror("");
  48.     }
  49. }
  50.  
  51.  
  52. #ifdef TESTIT
  53. main(ac,av)
  54.  int ac;
  55.  char *av[];
  56. {
  57.   Einit();
  58.   printf("%s\n",Ztimestring(Zfilemodtime(av[1])));
  59.   exit(0);
  60. }
  61. #endif
  62.  
  63.